package cn.nexd.app.collector.util;

import android.content.Context;

import com.umeng.analytics.MobclickAgent;

import cn.nexd.app.collector.BuildConfig;
import cn.nexd.utils.framework.tools.Logger;

/**
 * Created by wangxu on 16/12/5.
 */
public class UMengUtil {
    private static final String TAG = "UMengUtil";
    private static UMengUtil ourInstance = new UMengUtil();

    public static UMengUtil getInstance() {
        return ourInstance;
    }


    private UMengUtil() {
    }

    private static final boolean RELEASE = !BuildConfig.DEBUG;

    public void init(Context context) {
        if (RELEASE) {
            MobclickAgent.setScenarioType(context, MobclickAgent.EScenarioType.E_UM_ANALYTICS_OEM);
            MobclickAgent.setCatchUncaughtExceptions(true);
            MobclickAgent.setSessionContinueMillis(50000L);
            Logger.debug(TAG, "init: 初始化 UMeng SDK");
        }
    }

    public void onPause(Context context) {
        if (RELEASE) {
            MobclickAgent.onPause(context);
        }

    }

    public void onResume(Context context) {
        if (RELEASE) {
            MobclickAgent.onResume(context);
        }
    }

    public void reportError(Context context, Exception error) {
        if (RELEASE) {
            MobclickAgent.reportError(context, error);
        }
    }
}
